﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DapperWrapper;
using ZLWeb.WebApiEntity.EasyUse;
using ZLWeb.WebApiRepository.InterFace;
using DapperExtensions;

namespace ZLWeb.WebApiRepository
{
    public class PaymentRepository : Respository<AccInfo>, IPaymentRepository
    {
        public AccInfo GetAccInfo(string cardno, short ctype, short crdysign, short deldynosign)
        {
            AccInfo accinfo = new AccInfo();
            AccInfo item =
                ExecuteProcWithTemptable(accinfo, "test_pr_AccWallet_Query", "#AccInfo", false,
                    new {cardno, ctype, crdysign, deldynosign}).FirstOrDefault();
            if (error != null)
            {
                return new AccInfo() {errormodel = error};
            }
            return item;
        }

        public AccInfoResponse GetallAccInfo(string cardno, short ctype, short crdysign, short deldynosign)
        {
            AccInfoResponse accInfoResponse = new AccInfoResponse();
            WalletInfo walletInfo=new WalletInfo();
            Balanceinfo balanceinfo = new Balanceinfo();
            List<Action<IDbConnection>> paActions = new List<Action<IDbConnection>>();
            AccInfo accinfo = new AccInfo();
            var ac = ExecuteProcAddParam(accinfo, "#AccInfo", false);
            paActions.Add(ac);
            var ywInfoparam = ExecuteProcAddParam(walletInfo, "#WalletInfo", false);
            paActions.Add(ywInfoparam);
            var pnoparam = ExecuteProcAddParam(balanceinfo, "#Balanceinfo", false);
            paActions.Add(pnoparam);
            ExecuteProc(paActions, "pr_AccWallet_Query", new { cardno, ctype, crdysign, deldynosign }, (con) =>
            {
                accInfoResponse.AccInfo = con.GetList<AccInfo>().FirstOrDefault();
                accInfoResponse.WalletInfo = con.GetList<WalletInfo>().ToList();
                accInfoResponse.Balanceinfo = con.GetList<Balanceinfo>().FirstOrDefault();
            });

            return accInfoResponse;
        }

        public IEnumerable<WxMsg> GetWxMsg()
        {
            WxMsg accinfo = new WxMsg();
            IEnumerable<WxMsg> item = ExecuteProcWithTemptable(accinfo, "pr_WxMsgList_query", "#WxMsg", false, new {  });
            return item;
        }
    }
}
